//
//  LZManageReviewsRestaurantReviewsHeadInfoView.m
//  laziz_Merchant
//
//  Created by xbn_iMac on 2016/12/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZManageReviewsRestaurantReviewsHeadInfoView.h"
#import "LZRestaurantCommentInfoModel.h"
#import "LABaseKeyValueLabelView.h"
#import "HCSStarRatingView.h"
#import "Masonry.h"

@interface LZManageReviewsRestaurantReviewsHeadInfoView ()
{
    CGRect myframe;
}
@property (weak, nonatomic) IBOutlet UIView *starBgView;
@property (weak, nonatomic) IBOutlet UILabel *labNoReviewRemind;

@property (weak, nonatomic) IBOutlet LABaseKeyValueLabelView *tasteView;    // 味道评分
@property (weak, nonatomic) IBOutlet LABaseKeyValueLabelView *atmosphereView;   // 气氛评分
@property (weak, nonatomic) IBOutlet LABaseKeyValueLabelView *serviceView;  // 服务评分

@property (weak, nonatomic) HCSStarRatingView *starRatingView;


@end

@implementation LZManageReviewsRestaurantReviewsHeadInfoView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"LZManageReviewsRestaurantReviewsHeadInfoView" owner:nil options:nil];
        self=[nibs objectAtIndex:0];
        self.frame = frame;
        myframe = frame;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    self.labNoReviewRemind.hidden = YES;
    self.labNoReviewRemind.text = LZLocalizedString(@"review_norating_now", nil);
    self.starBgView.backgroundColor = [UIColor clearColor];
    /*
     ==========================================Star =================================================
     */
    
    int number = 5;
    HCSStarRatingView *star = [[HCSStarRatingView alloc]initWithFrame:CGRectZero];
    star.maximumValue = number;
    star.minimumValue = 0;
    star.spacing = 2.5;
    star.allowsHalfStars = YES;
    star.accurateHalfStars = YES;
    star.tintColor = UIColorFromRGB(0xF08F4D, 1);
    star.userInteractionEnabled = NO;
    
    self.starRatingView = star;
    
    [self.starBgView addSubview:star];
    
    [star makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.starBgView);
    }];
}

- (void)setModel:(LZRestaurantCommentInfoModel *)model {
    
    BOOL isHaveReview = [model.restaurantScore floatValue]>0;
    // 星星指数
    self.starRatingView.hidden = !isHaveReview;
    self.labNoReviewRemind.hidden = isHaveReview;
    if (isHaveReview) {
        self.starRatingView.value = [model.restaurantScore floatValue];
    }
    
    [self.tasteView setKey:LZLocalizedString(@"taste", nil) andValue:model.tasteScore?:@"0.0"];
    [self.atmosphereView setKey:LZLocalizedString(@"atmosphere", nil) andValue:model.environmentScore?:@"0.0"];
    [self.serviceView setKey:LZLocalizedString(@"service", nil) andValue:model.serviceScore?:@"0.0"];
}


- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    self.frame = myframe;    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
